package com.demo.springbootdemo.domain.query;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.springbootdemo.domain.po.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("用户查询参数")
public class UserQuery extends PageQuery {
    @ApiModelProperty(value = "用户名", example = "t")
    private String name;

    @ApiModelProperty(value = "状态", example = "1")
    private Integer status;

    @ApiModelProperty(value = "最小金额", example = "100")
    private Integer minBalance;

    @ApiModelProperty(value = "最大金额", example = "10000")
    private Integer maxBalance;

    public <T> Page<T> toMpPage() {
        Page<T> page = Page.of(this.getPageNo(), this.getPageSize());

        OrderItem orderItem = new OrderItem();
        if (StrUtil.isBlank(this.getOrderBy())) {
            orderItem.setColumn("update_time");
        } else {
            orderItem.setColumn(this.getOrderBy());
        }
        orderItem.setAsc(this.getIsAsc());
        page.addOrder(orderItem);

        return page;
    }
}
